import Vue from 'vue'
import App from './App'
import router from './router'

import 'mint-ui/lib/style.css'

Vue.config.productionTip = false

import VueClipboard from 'vue-clipboard2'

VueClipboard.config.autoSetContainer = true // add this line
Vue.use(VueClipboard)

//fastclick
import FastClick from 'fastclick'

document.addEventListener('DOMContentLoaded', function () {
  FastClick.attach(document.body);
}, false);

import 'common/base.css'
import 'src/iconfont/iconfont.css'

router.afterEach((to, from, next) => {
  window.scrollTo(0, 0);
});

import {getQueryVariable} from './utils/utils'

const orderNum = getQueryVariable('orderNum')
const openId = getQueryVariable('openId')

if (!orderNum) {
  alert('订单号获取错误')
}
if (!openId) {
  alert('openId获取错误')
}
console.log(openId)
console.log(orderNum)

import {findone} from 'src/api/api'

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App),
  data() {
    return {
      openId: openId,
      orderNum: orderNum,
      resultObj: {},


      personalNumUrlArray: [],
      elemString: '',
      storeNameString:'',//店铺*转输入框后的内容
      payTaobaoOrder: '',//拍手填写的淘宝付款单号
      realPayMoney:0,//实际付款金额
      otherCondition: [],
      personalFollow: [],
      searchTypeValue:[],//关键词搜索时，多个关键字转换为数组
      priceBetween:[],//价格区间
      personalDeepRead:[],//深度浏览（收藏、加购、假聊）
      title1: '',
      title3: '',

      personalNumUrl: '',
      goodAppraiseDate: '',
      personalSameStoreReadUrl: ''
    }
  },
  created() {
    findone(this.orderNum,openId).then(res => {
      let data = res.resultObj;
      this.otherCondition = data.otherCondition.split(',');
      if (data.priceBetween){
        this.priceBetween = data.priceBetween.split('-');
        if (this.priceBetween[1] == 'NaN'){
          this.priceBetween[1] = "*";
        }
      }


      this.resultObj = res.resultObj;

      this.resultObj.zhaoChaArray.split('|').forEach(function (val) {
        let itemStr = val.replace(/\*/g, '<input type="text" maxlength="1">')
        this.elemString = this.elemString + '<div>' + itemStr + '</div>'
      }, this)
      //填写店铺名称  store_name
      let storeStr = this.resultObj.storeName.replace(/\*/g, '<input type="text" maxlength="1">');
      this.storeNameString = this.storeNameString + '<div>' + storeStr + '</div>'
      // 格式化 关键词搜索的列表
      if (this.resultObj.searchTypeName == '关键词搜索') {
        this.searchTypeValue = this.resultObj.searchTypeValue.split(",");
      }
      //跨店货比
      if (this.resultObj.personalNum != undefined && this.resultObj.personalNum != '' && this.resultObj.personalNum != 'null') {
        this.resultObj.personalNum = parseInt(this.resultObj.personalNum);
        this.personalNumUrlArray = new Array(this.resultObj.personalNum)
      }
      //同店铺浏览
      if (this.resultObj.personalSameStoreRead != undefined && this.resultObj.personalSameStoreRead != '' && this.resultObj.personalSameStoreRead != 'null') {
        this.resultObj.personalSameStoreRead = parseInt(this.resultObj.personalSameStoreRead);
        this.personalSameStoreReadArray = new Array(this.resultObj.personalSameStoreRead)
      }
      // this.resultObj.goodAppraiseDate = '';

      if (this.resultObj.personalFollow != '' && this.resultObj.personalFollow != undefined) {
        this.personalFollow = this.resultObj.personalFollow.split(',');
      }
      if (this.resultObj.personalDeepRead){//如果不为空
        this.personalDeepRead = this.resultObj.personalDeepRead.split(",");

      }
      this.resultObj.searchTypeName = this.resultObj.searchTypeName || ''

      // this.title1 = `${this.resultObj.searchTypeName}`
      // this.title3 = `货比${this.resultObj.personalNum}家`
    })

    // this.resultObj = {
    //     "completeDate": "2019-04-12 17:38:46",
    //     "createDate": "2019-04-12 17:38:46",
    //     "goodAppraise": "不知道大家的体验怎么样，个人第一次用，感觉还是比较满意的",
    //     "orderNum": "2116636770209890305",
    //     "orderPerMoney": 15,
    //     "orderProgressCount": 1,
    //     "orderTotalMoney": 150,
    //     "orderType": 1,
    //     "otherCondition": "包邮,天猫,全球购",
    //     "ownerId": "掌柜ID",
    //     "paishouPerMoney": 9,
    //     "payKeyword": "移动联通电信4G",
    //     "payMessage": "花呗付款",
    //     "payPrice": 469.99,
    //     "personalDeepRead": "随机加购收藏假聊",
    //     "personalDiscount": "优惠券",
    //     "personalDiscount2": "天猫积分(原价返款)",
    //     "personalFollow": "关注,商家聊天",
    //     "personalNote": "无垃圾分类数据了就是浪费的福建省数量的分解落实经费落实经费了肯定就是离开房间数量多交流看法是否",
    //     "personalNum": "货比一家,货比二家,货比三家",
    //     "personalOrderCount": 10,
    //     "personalSameStoreRead": "随机逛店1-3款",
    //     "priceBetween": "4000-5000",
    //     "productName": "Apple iPhone 8 Plus",
    //     "productUrl": "https://item.jd.com/5089275.html",
    //     "searchTypeName": "关键词搜索searchTypeName",
    //     "sellerName": "shiro测试帐号",
    //     "sellerTelephone": "18612121217",
    //     "sendAddress": "湖北省/武汉市/洪山区",
    //     "sortTypeName": "销量排序",
    //     "storeName": "Apple产品京东自营旗舰店",
    //     "timingPublishTime": "1",
    //     "validateStatus": 1,
    //     "zhaoChaArray": "5.5英寸*膜*清显示屏,由平台卖家*供发票和相应的售后服务|凭厂商维*中心或特*维修*的质量测证明",
    //     "searchTypeValue": ""
    // }
    // this.otherCondition = this.resultObj.otherCondition.split(',')
    // this.resultObj.personalNum = 3
    // this.personalNumUrlArray = new Array(this.resultObj.personalNum)
    // this.resultObj.goodAppraiseDate = ''
    // this.resultObj.zhaoChaArray.split('|').forEach(function(val) {
    //     let itemStr = val.replace(/\*/g, '<input type="text" maxlength="1">')
    //     this.elemString = this.elemString + '<div>' + itemStr + '</div>'
    // }, this)
    // this.personalFollow = this.resultObj.personalFollow.split(',')
    // this.resultObj.searchTypeName = this.resultObj.searchTypeName || ''
  }
})
